/*******************************************************************************
 * Copyright (c) 2011 Olexandr V. Shaposhnikov.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Olexandr V. Shaposhnikov - initial API and implementation and/or initial documentation
 *******************************************************************************/
package com.funkyroach.use.ui.editor;

import org.eclipse.dltk.core.IDLTKLanguageToolkit;
import org.eclipse.dltk.internal.ui.actions.FoldingActionGroup;
import org.eclipse.dltk.internal.ui.editor.ScriptEditor;
import org.eclipse.dltk.internal.ui.editor.ScriptOutlinePage;
import org.eclipse.dltk.ui.text.ScriptTextTools;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IDocumentExtension3;
import org.eclipse.ui.IEditorInput;

import com.funkyroach.use.core.language.USLanguageToolkit;
import com.funkyroach.use.plugin.USPlugin;
import com.funkyroach.use.ui.outline.USOutlinePage;
import com.funkyroach.use.ui.text.IUSPartitionTokens;

public class USScriptEditor extends ScriptEditor {

	private static final String UDK_EDITOR_ID = "com.funkyroach.use.ui.editor";

	protected void initializeEditor() {
		super.initializeEditor();
		// initialize
	}

	public void dispose() {
		// dispose
		super.dispose();
	}

	@Override
	public String getEditorId() {
		return UDK_EDITOR_ID;
	}

	@Override
	public IDLTKLanguageToolkit getLanguageToolkit() {
		return USLanguageToolkit.getDefault();
	}

	@Override
	public IPreferenceStore getScriptPreferenceStore() {
		return USPlugin.instance().getPreferenceStore();
	}

	protected ScriptOutlinePage doCreateOutlinePage() {
		return new USOutlinePage(this, USPlugin.instance().getPreferenceStore());
	}

	public ScriptTextTools getTextTools() {
		return USPlugin.instance().getTextTools();
	}

	protected void connectPartitioningToElement(IEditorInput input,
			IDocument document) {
		if (document instanceof IDocumentExtension3) {
			IDocumentExtension3 extension = (IDocumentExtension3) document;
			if (extension
					.getDocumentPartitioner(IUSPartitionTokens.US_PARTITIONING) == null) {
				USDocumentSetupParticipant participant = new USDocumentSetupParticipant();
				participant.setup(document);
			}
		}
	}

	protected FoldingActionGroup createFoldingActionGroup() {
		return new FoldingActionGroup(this, getViewer(), USPlugin.instance()
				.getPreferenceStore());
	}

}